package com.sto.stoapp.activity.sales;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.adapter.SoleAdapter;
import com.sto.stoapp.broadcast.HomeBroadAction;
import com.sto.stoapp.entity.FunctionEntity;
import com.sto.stoapp.widget.StoHomeActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * 签收
 * 
 * @author mgf
 * 
 */
public class SalesSignInActivity extends StoHomeActivity {
    // 按键映射
    private static final int[] MAPP_TO_KEY = { R.string.one_sign,
            R.string.more_sign , R.string.more_sign_photo ,R.string.help_sign};
	private ListView SignFuncList;
	private SoleAdapter SignListAdapter;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sto_sales_sign_in);
		this.setTitleBottom(R.string.sign_in, HomeBroadAction.SALES_MAN_BROAD);
		initWidget();
	}
	
	private void initWidget() {
		SignFuncList = (ListView)findViewById(R.id.sales_sign_func_list);
		SignListAdapter = new SoleAdapter(this, getResourceList());
		SignFuncList.setAdapter(SignListAdapter);
		
		SignFuncList.setOnItemClickListener(new OnItemClickListener() {
			
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				arg1.setSelected(true);
				TextView title = (TextView) arg1.findViewById(R.id.res_test);
				clickItemEvent(title.getText().toString());
			}
			
		});
		
	}
	
	private void clickItemEvent(String title) {
		// 单票签收
		if (title.equals(getText(R.string.one_sign))) {
			Intent intent = new Intent(this, SalesSignContentActivity.class);
			intent.putExtra("title", R.string.one_sign);
//			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(intent);
		}
		// 多票签收
		else if (title.equals(getText(R.string.more_sign))) {
			Intent intent = new Intent(this, SalesSignContentActivity.class);
			intent.putExtra("title", R.string.more_sign);
//			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(intent);
		}
		// 拍照签收
		else if(title.equals(getText(R.string.more_sign_photo))){
			Intent intent = new Intent(this, SalesSignPiecePhotoActivity.class);
			intent.putExtra("busiType", HomeBroadAction.SALES_MAN_BROAD);
//			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(intent);
		}
		//代收签收
		else if(title.equals(getText(R.string.help_sign))){
			Intent intent=new Intent(this,SalesSignHelpActivity.class);
			intent.putExtra("title", R.string.help_sign);
			startActivity(intent);
		}
		else{
			
		}
	}
	
	private List<FunctionEntity> getResourceList() {
		List<String> resList = new ArrayList<String>();
		resList.add(getText(R.string.one_sign).toString());
		resList.add(getText(R.string.more_sign).toString());
		resList.add(getText(R.string.more_sign_photo).toString());
		resList.add(getText(R.string.help_sign).toString());
		List<FunctionEntity> functionList = new ArrayList<FunctionEntity>();
		for (String res : resList) {
			FunctionEntity entity = new FunctionEntity();
			entity.setTitle(res);
			functionList.add(entity);
		}
		return functionList;
	}
	

	

}
